package com.travel.api.service.oss

import org.springframework.web.multipart.MultipartFile
import java.net.URL

interface OSSService {

    /**
     * 创建存储空间
     * @param bucketName
     */
    fun create(bucketName: String): Boolean

    /**
     * OSS文件夹创建
     */
    fun createFolder(bucketName :String?, folderName: String): Boolean
    fun createFolder(folderName: String) = createFolder(null, folderName)

    /**
     * OSS对象存储
     * @param content
     */
    fun upload(bucketName :String?, objectName: String, content: String): Boolean
    fun upload(objectName: String, content: String) = upload(null, objectName, content)

    /**
     * OSS对象下载
     * @param bucketName
     * @param objectName
     * @return
     */
    fun download(bucketName: String?, objectName: String): String?
    fun download(objectName: String) = download(null,objectName)

    /**
     * OSS对象删除
     * @param bucketName
     * @param objectName
     * @return
     */
    fun delete(bucketName: String, objectName: String?): Boolean
    fun delete(bucketName: String) = delete(bucketName ,null)

    /**
     * OSS对象列举
     * @param name
     * @return
     */
    fun list(bucketName: String): List<String>

    /**
     * OSS文件上传
     * @param bucketName
     * @param folder
     * @param file
     */
    fun uploadFile(bucketName: String?,folder: String?,file: MultipartFile): URL?
    fun uploadFile(file: MultipartFile) = uploadFile(null, null, file)
}
